package com.szh.zx.gaoDingJavaBook.chapter3.one;


import java.util.AbstractMap;
import java.util.HashSet;
import java.util.Map;

class SimpleEntry<K,V> implements Map.Entry<K,V>,java.io.Serializable{
	private K key;
	private V value;
// 定义俩个构造器
	public SimpleEntry(Map.Entry<? extends  K,? extends  V > entry){
		this.key = entry.getKey();
		this.value = entry.getValue();
	}
	public SimpleEntry(K key, V value) {
		this.key = key;
		this.value = value;
	}

	@Override
	public K getKey() {
		return key;
	}

	@Override
	public V getValue() {
		return value;
	}
// 改变该key-value 对的value值
	@Override
	public V setValue(V value) {
		V oldValue = this.value;
		this.value = value;
		return oldValue;
	}
// 根据key 比较12 个simpleEntry 是否相等
	@Override
	public boolean equals(Object obj) {
		if (obj == this){
			return true;
		}
		if (obj.getClass() == SimpleEntry.class){
			SimpleEntry simpleEntry = (SimpleEntry) obj;
			return simpleEntry.getKey().equals(getKey());
		}
		return false;
	}

	@Override
	public int hashCode() {
		return key == null ? 0:key.hashCode();
	}

	@Override
	public String toString() {
		return key+ "="+value;
	}
}
// 继承实现一个map
public class Set2Map extends HashSet< SimpleEntry> {
}
